package co.fitstart.scheduler.job;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import co.fitstart.scheduler.service.FinishedCourseReportService;
import co.fitstart.scheduler.service.RevenueReportService;
import co.fitstart.scheduler.service.VisitorReportService;

@Component
public class ReportJob {
    
    private static final Logger logger = LoggerFactory.getLogger(ReportJob.class);
    
    @Autowired
    private RevenueReportService revenueReportService;
    
    @Autowired
    private FinishedCourseReportService finishedCourseReportService;
    
    @Autowired
    private VisitorReportService visitorReportService;
    
    /**
     * 
     * 
     * run at 2:10 am every day FIXME
     */
    @Scheduled(cron = "0 5 1 * * *")
    public void scanCreateRevenueReport() {
        
        logger.info("start running ReportJob#scanCreateRevenueReport#createPurchaseReport at {}", new Date());
        revenueReportService.createPurchaseReport();
        logger.info("finish running ReportJob#scanCreateRevenueReport#createPurchaseReport at {}", new Date());
        
        logger.info("start running ReportJob#scanCreateRevenueReport#createRefundReport at {}", new Date());
        revenueReportService.createRefundReport();
        logger.info("finish running ReportJob#scanCreateRevenueReport#createRefundReport at {}", new Date());
        
    }
    
//    @Scheduled(cron = "0 15 11 2 * ?")
//    public void scanCreateRevenueReport1() {
//        Date day = DateUtils.parseDate("2018-12-28 01:05:00", "yyyy-MM-dd HH:mm:ss");
//        
//        logger.info("start running ReportJob#scanCreateRevenueReport#createPurchaseReport at {}", day);
//        revenueReportService.createPurchaseReport(day);
//        logger.info("finish running ReportJob#scanCreateRevenueReport#createPurchaseReport at {}", day);
//        
//        logger.info("start running ReportJob#scanCreateRevenueReport#createRefundReport at {}", day);
//        revenueReportService.createRefundReport(day);
//        logger.info("finish running ReportJob#scanCreateRevenueReport#createRefundReport at {}", day);
//        
//        logger.info("start running ReportJob#scanCreateFinishedCourseReport at {}", day);
//        finishedCourseReportService.createFinishedCourseReport(day);
//        logger.info("finish running ReportJob#scanCreateFinishedCourseReport at {}", day);
//        
//        logger.info("start running ReportJob#scanCreateVisitorReport at {}", day);
//        visitorReportService.createVisitorReport(day);
//        logger.info("finish running ReportJob#scanCreateVisitorReport at {}", day);
//    }
    
    /**
     * 
     * 
     * run at 2:10 am every day FIXME
     */
    @Scheduled(cron = "0 30 1 * * *")
    public void scanCreateFinishedCourseReport() {
        
        logger.info("start running ReportJob#scanCreateFinishedCourseReport at {}", new Date());
        finishedCourseReportService.createFinishedCourseReport();
        logger.info("finish running ReportJob#scanCreateFinishedCourseReport at {}", new Date());
        
    }
    
    /**
     * 
     * 
     * run at 2:10 am every day FIXME
     */
    @Scheduled(cron = "0 0 1 * * *")
    public void scanCreateVisitorReport() {
        
        logger.info("start running ReportJob#scanCreateVisitorReport at {}", new Date());
        visitorReportService.createVisitorReport();
        logger.info("finish running ReportJob#scanCreateVisitorReport at {}", new Date());
        
    }
    
}
